package secondStage.part5.多线程.多线程的实现方式一;

/**
 * @ClassName: [ThreadSleepDemo]
 * @Description: 线程优先级
 * @Author: [黄劲松]
 * @CreateDate: [2021-04-05]
 * @Version: [v1.0]
 */
/*
    Thread类中设置和获取线程优先级的方法
    ●public final int getPriority(): 返回此线程的优先级
    ●public final void setPriority(int newPriority):更改此线程的优先级
    线程默认优先级是5;线程优先级的范围是: 1-10
    线程优先级高仅仅表示线程获取的CPU时间片的几高，但是要在次数比较多,或者多次运行的时候才能看到你想要的效果
*/
public class ThreadPriorityDemo {
    public static void main(String[] args) {
        MyThread2 my1 = new MyThread2();
        MyThread2 my2 = new MyThread2();
        MyThread2 my3 = new MyThread2();
        my1.setName("飞机");
        my2.setName("汽车");
        my3.setName("高铁");

        //public final int getPriority(): 返回此线程的优先级
        /*System.out.println(my1.getPriority());
        System.out.println(my2.getPriority());
        System.out.println(my3.getPriority());*/

        //public final void setPriority(int newPriority):更改此线程的优先级
        //my1.setPriority(100000);//IllegalArgumentException异常
        /*System.out.println("最高优先级："+Thread.MAX_PRIORITY);//10
        System.out.println("最低优先级："+Thread.MIN_PRIORITY);//1
        System.out.println("默认优先级："+Thread.NORM_PRIORITY);//5*/
        my1.setPriority(5);
        my2.setPriority(10);
        my3.setPriority(1);
        //启动线程
        my1.start();
        my2.start();
        my3.start();
    }
}
